using System.Collections.Generic;
using Backpack;
using SO;
using UnityEngine;
public interface ICombineSystem
{
    public int Combine();
    public void AddItemToCombine(ItemDataSO itemDataSO);
    public bool IsCombinng { get; set; }
    public HashSet<ItemDataSO> ItemToCombine { get; }
}
public class CombineSystem : ICombineSystem, ICanTriggerEvent
{
    private bool isCombining = false;
    private CombineInfomationModel model = CombineInfomationModel.Instance;
    private HashSet<ItemDataSO> itemToCombine = new HashSet<ItemDataSO>();

    public static ICombineSystem Instance = new CombineSystem();

    public bool IsCombinng { get => isCombining; set => isCombining = value; }

    public HashSet<ItemDataSO> ItemToCombine => itemToCombine;

    public CombineSystem()
    {

    }

    public void AddItemToCombine(ItemDataSO itemDataSO)
    {
        itemToCombine.Add(itemDataSO);
    }
    public int Combine()
    {
        List<CombineInfomation> combineInfoList = model.combineInformationSO.combineInfomations;
        for (int i = 0; i < combineInfoList.Count; ++i)
        {
            if (combineInfoList[i].combineIds.Count != itemToCombine.Count)
            {
                continue;
            }
            //TODO : Check itemToCombine with combineInfoList[i].combineIds
            List<int> itemIds = new List<int>(combineInfoList[i].combineIds);

            foreach (var itemData in itemToCombine)
            {
                if (itemIds.Contains(itemData.id))
                {
                    itemIds.Remove(itemData.id);
                }
            }
            if (itemIds.Count == 0)
            {
                //生成新物体
                return combineInfoList[i].targetId;
            }
        }
        return -1;
    }
}
public struct GenerateItemInBackpackEvent
{
    public ItemDataSO itemDataSO;
    public GenerateItemInBackpackEvent(ItemDataSO itemDataSO)
    {
        this.itemDataSO = itemDataSO;
    }
}